// 点击键盘，改变boxConfig
addEventListener("keydown", (e) => {

	/* 修改数据 */
	const { left, top, width, height } = boxDom.getBoundingClientRect()
	if (e.key === 'ArrowRight') {
		boxConfig.left = left + boxConfig.step
	} else if (e.key === "ArrowLeft") {
		boxConfig.left = left - boxConfig.step
	} else if (e.key === "ArrowUp") {

		boxConfig.top = top - boxConfig.step
	} else if (e.key === "ArrowDown") {
		boxConfig.top = top + boxConfig.step
	}
	boxConfig.width = width
	boxConfig.height = height
	/* 更新DOM */
	renderBox()
	renderInfo()
})

textDom.onblur = () => {
	boxConfig.text = `${textDom.value}`
	renderBox()
}

tempDom.onblur = () => {
	boxConfig.text = `${tempDom.value}`
	renderBox()
}

frequencyDom.onblur = () => {
	boxConfig.frequency = `${Number(frequencyDom.value)}`
	renderBox()
}

/* 碰撞检测 */
setInterval(() => {
	const { right, top, bottom, left } = boxDom.getBoundingClientRect()

	if (right < innerWidth && top <= 0) {
		// 传，无限+拼接，授
		boxConfig.left += boxConfig.step;
	}
	else if (right >= innerWidth && bottom < innerHeight) {
		boxConfig.top += boxConfig.step;
	}
	else if (right <= innerWidth && innerHeight <= bottom && left > 0) {
		boxConfig.left -= boxConfig.step;
	}
	else if (left >= 0 && top >= 0) {
		boxConfig.top -= boxConfig.step;
	}
	renderBox()
}, boxConfig.frequency)